package com.cim.service.impl;

import com.cim.dao.CourseAccountDao;
import com.cim.pojo.CourseAccount;
import com.cim.service.CourseAccountService;
import com.cim.utils.CharUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseAccountServiceImpl implements CourseAccountService {
    @Autowired
    private CourseAccountDao courseAccountDao;
    public List<CourseAccount> findCourseAccount(CourseAccount ca) {
        List<CourseAccount> list=courseAccountDao.findCourseAccount(ca);
        return list;
    }

    public int addCourseAccounts(List<CourseAccount> cas) {
        int count=0;
        for(CourseAccount ca:cas){
            addCourseAccount(ca);
            count++;
        }
        return count;
    }
    public CourseAccount addCourseAccount(CourseAccount ca) {
        String id= CharUtil.getUUID(10);
        ca.setCourseAccountId(id);
        courseAccountDao.addCourseAccount(ca);
        return ca;
    }
    public int deleteCourseAccount(String id) {
        return courseAccountDao.deleteCourseAccount(id);
    }

    public int updateCourseAccount(CourseAccount ca) {
        return courseAccountDao.updateCourseAccount(ca);
    }

    @Override
    public CourseAccount findByCA(String accountId, String courseId) {
        return  courseAccountDao.findByCA(accountId, courseId);
    }

    public int deleteCourseAccountByCourseId(String courseId){
        return courseAccountDao.deleteCourseAccountByCourseId(courseId);
    }
}
